<%@page import="java.security.MessageDigest"%>
<%@page import="java.sql.ResultSet"%>
<%@page import="conectar.Conectar"%>
<%@page session="true" %>
<!DOCTYPE html>
<html>
    <head>
        <link type="text/css" href="css/default.css" rel="stylesheet">
        <link type="text/css" href="css/style.css" rel="stylesheet">
        <link type="text/css" href="css/admin.css" rel="stylesheet">
    </head>
    <body>
        <p>Confirmar para continuar</p>
        <%
            String usuario = "";
            String clave = "";
            String status = "";
            String llaves = "";
            usuario = request.getParameter("usuario");
            clave = request.getParameter("clave");
            
            // -----------------------INICIO MD5 ------------------------------
    
        MessageDigest mdAlgorithm = MessageDigest.getInstance("MD5");
        mdAlgorithm.update(clave.getBytes());

        byte[] digest = mdAlgorithm.digest();
        StringBuffer hexString = new StringBuffer();

        for (int i = 0; i < digest.length; i++)
        
            {
                clave = Integer.toHexString(0xFF & digest[i]);

                if (clave.length() < 2) 
                    {
                        clave = "0" + clave;
                    }

                hexString.append(clave);
            }

        clave= hexString.toString();
        
     // -----------------------FIN MD5 ------------------------------
        
            String valorAcepted = "1";
            try {
                conectar.Conectar miconexion = new Conectar();
                String sql = "SELECT * FROM `Votante` WHERE `PersonaIFE` =" + usuario + " AND `password` ='" + clave + "'";
                ResultSet consulta = miconexion.consulta(sql);
                if (consulta.next()) {
                    status = consulta.getString(3);
                    llaves = consulta.getString(5);
                    if(status.equals(valorAcepted)){
                        if (llaves.equals(valorAcepted)) {%>
                            <div class="wrapper">
                                <div id="login" class="animate form" >
                                <form action="generarllaves.jsp" method="post" >
                                    <h1>Se van a generar llaves </h1>
                                        <p style="font-size: 20px; font-weight: normal "> 
                                            <label>Para continuar con el proceso, ingresa los siguientes datos</label>
                                        </p>
                                        <p style="font-size: 20px; font-weight: normal "> 
                                            <label> Confirma tu IFE</label>               
                                            <input id="userife" name="usuario" required="required" type="text" placeholder="mi ife"  />

                                        </p>
                                        <p class="add button"> 
                                            <a>
                                                <input type="submit" value="Continuar" /> 
                                            </a>
                                        </p>
                                    </form>
                                </div>
                            </div>
                    <%} else {
                        %>
                        <jsp:forward page="tarjeton.jsp"/>
                        <%
                        }
                    }
                    else{
                                          %>
                        <jsp:forward page="final.jsp"/>
                        <%         
                    }
                }
                miconexion.desconectar();
            } catch (Exception e) {
                out.println(e.getMessage());
            }
        %>
    </body>
</html>